﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//.............
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//...................

namespace QLKTX1._0.DAO
{
    class NamDAO
    {
        public static List<NamDTO> dsNam()
        {
            List<NamDTO> dsNam = new List<NamDTO>();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM Nam");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                NamDTO nam = new NamDTO();

                nam.MaNam = Int32.Parse (dt.Rows[i]["maNam"].ToString());

                nam.TenNam = dt.Rows[i]["tenNam"].ToString();
         
                dsNam.Add(nam );
            }
            return dsNam;
        }

        //ham insert
        public static bool themNam(NamDTO nam)
        {

            ConnectDB con = new ConnectDB();// dung DB

            return con.executeQuery("INSERT INTO Nam(maNam,tenNam) VALUES('" + nam.MaNam + "','" + nam.TenNam + "')");

        }
        //ham delete
        public static bool xoaNam(NamDTO nam)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("DELETE FROM Nam WHERE maNam='" + nam.MaNam + "'");
        }
        //ham update
        public static bool capNhatNam(NamDTO nam)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("UPDATE Nam set tenNam='" + nam.TenNam + "' WHERE maNam='" + nam.MaNam + "'");
        }
    }
}
